package cn.ekgc.hbase;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;

public class PutDemo {
    static byte[] cf1=Bytes.toBytes("personalinfo");
    static byte[] cf2=Bytes.toBytes("recordinfo");
    static byte[] cf3=Bytes.toBytes("assetsinfo");
    public static void main(String[] args) throws Exception {
        Configuration config = HBaseConfiguration.create(); //获取链接信息
        //创建表
        //创建链接
        try (Connection connection = ConnectionFactory.createConnection(config)) {
            Admin admin = connection.getAdmin();
            System.out.print("put row into  table. ");
            //do put
            Put put = new Put(Bytes.toBytes("row-0001"));

            put.addColumn(cf1,Bytes.toBytes("nickname"),Bytes.toBytes("张三"));
            put.addColumn(cf2,Bytes.toBytes("gameName"),Bytes.toBytes("LOL"));
            put.addColumn(cf2,Bytes.toBytes("paiming"),Bytes.toBytes("5"));
            put.addColumn(cf3,Bytes.toBytes("qqbi"),Bytes.toBytes("5000000000000"));

            HTable table  = (HTable) connection.getTable(TableName.valueOf("gamer"));
            table.put(put);

            System.out.println(" Done.");

        }
    }
}
